//
//  ShareOpenListHeaderView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/14.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ShareOpenListHeaderView.h"

#import "ShareOpenMenuModel.h"
@interface ShareOpenListHeaderView ()
/**  视图数组  */
@property (strong, nonatomic) NSMutableArray  *viewArray;

@end
@implementation ShareOpenListHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        
            TenGrayShadowView *under = [TenGrayShadowView new];
            under.backgroundColor = [UIColor themeGrayColor];
            [self addSubview:under];
            under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(10 * [UIScreen zj_screenHScale]);
        
        [self addSubview:self.seleLabel];
        [self addSubview:self.seleTypeLabel];
        self.seleLabel.sd_layout
        .bottomSpaceToView(under, 0)
        .leftSpaceToView(self, 0)
        .widthIs(self.seleLabel.width)
        .heightIs(40 * [UIScreen zj_screenHScale]);
        
        self.seleTypeLabel.sd_layout
        .bottomSpaceToView(under, 0)
        .rightSpaceToView(self, 0)
        .widthIs(self.seleTypeLabel.width)
        .heightIs(40 * [UIScreen zj_screenHScale]);
        //分割线
        UIView *underView = [UIView new];
        underView.backgroundColor = under.backgroundColor;
        //分割线
        UIView *underView1 = [UIView new];
        underView1.backgroundColor = under.backgroundColor;
        
        [self addSubview:underView];
        [self addSubview:underView1];
        underView.sd_layout
        .bottomSpaceToView(self.seleLabel, 0)
        .leftEqualToView(self.seleLabel)
        .rightEqualToView(self.seleTypeLabel)
        .heightIs(1);
        
        underView1.sd_layout
        .topEqualToView(self.seleTypeLabel)
        .leftSpaceToView(self.seleLabel, 0)
        .widthIs(1)
        .heightRatioToView(self.seleLabel, 1);
    
        
    }
    return self;
}

- (void)setHeaderArray:(NSArray *)headerArray{
    _headerArray = headerArray;
    CGFloat width = [UIScreen zj_screenWith] / headerArray.count;
    for (int i = 0; i < headerArray.count; i ++) {
        ShareOpenMenuModel *model = headerArray[i];
        DiscoveryOneMenuView *one = [[DiscoveryOneMenuView alloc] initWithFrame:CGRectMake(width * i, 0, width, 130 * [UIScreen zj_screenHScale])];
        NSString *title = [NSString stringWithFormat:@"%@(%@)",model.title,model.number];
        one.titleString = title;
        one.imageString = model.imageString;
        one.tag = i;
        one.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
        [one addGestureRecognizer:tap];
        [self addSubview:one];
        
        if (i == 0) {
            self.requestView = one;
            one.label.textColor = [UIColor themeColor];
            one.isShow = YES;
        }else if (i == 1){
            self.resouceView = one;
            one.isShow = NO;
        }else{
            self.xiangmuView = one;
            one.isShow = NO;
        }
        
    }
}

- (void)tapClick:(UITapGestureRecognizer *)tap{
    if (self.delegate) {
        [self.delegate ShareOpenListHeaderView_index:tap.view.tag];
    }
}

- (void)showPopMenu:(UITapGestureRecognizer *)tap{
    if ([tap.view isKindOfClass:[ZJDownLabelView class]]) {
        ZJDownLabelView *view = (ZJDownLabelView *)tap.view;
        if (self.delegate) {
            [self.delegate ShareOpenListHeaderView_showPopMenu_view:(view)];
        }
    }
    
}

- (ZJDownLabelView *)seleLabel{
    if (_seleLabel == nil){
        _seleLabel = [[ZJDownLabelView alloc] initWithFrame:CGRectMake(0, 0, (self.width - 1) / 2, 40 * [UIScreen zj_screenHScale])];
        _seleLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showPopMenu:)];
        [_seleLabel addGestureRecognizer:tapGest];
        _seleLabel.textLabel.text = @"分类 : 所有";
    }
    return _seleLabel;
}
- (ZJDownLabelView *)seleTypeLabel{
    if (_seleTypeLabel == nil){
        _seleTypeLabel = [[ZJDownLabelView alloc] initWithFrame:CGRectMake(0, 0, (self.width - 1) / 2, 40 * [UIScreen zj_screenHScale])];
        _seleTypeLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showPopMenu:)];
        [_seleTypeLabel addGestureRecognizer:tapGest];
        _seleTypeLabel.textLabel.text = @"状态 : 所有";
    }
    return _seleTypeLabel;
}

@end
